package com.shujia.java.day18.demo5;

/**
 * @Description: ClimbThreadDemo  中年人 老年人 爬山(长度固定) 中年人2->100  老年人5
 * @Author: 王火火
 * @Date: 2019/8/20 14:10
 */


public class ClimbThreadDemo extends Thread {
    private int time;//爬100米用时间(爬100米休息时间)
    private int len;//爬了多少100米

    //传递name time kilo
    public ClimbThreadDemo(String name, int time, int kilo) {
        setName(name);
        this.time = time;
        this.len = kilo * 1000 / 100;
    }
    //爬山次数
    @Override
    public void run() {
        //len大于0 爬山
        while (len > 0) {
            System.out.println(getName() + "爬了100米");
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            len--;
        }
        System.out.println(getName()+"爬完了");
    }
}
